package com.ruoyi.insurance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.insurance.domain.EvaluateBeforeInsurance;
import com.ruoyi.insurance.service.IEvaluateBeforeInsuranceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保前安全评测Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/insurance/insurance_before")
public class EvaluateBeforeInsuranceController extends BaseController
{
    @Autowired
    private IEvaluateBeforeInsuranceService evaluateBeforeInsuranceService;

    /**
     * 查询保前安全评测列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:insurance_before:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluateBeforeInsurance evaluateBeforeInsurance)
    {
        startPage();
        List<EvaluateBeforeInsurance> list = evaluateBeforeInsuranceService.selectEvaluateBeforeInsuranceList(evaluateBeforeInsurance);
        return getDataTable(list);
    }

    /**
     * 导出保前安全评测列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:insurance_before:export')")
    @Log(title = "保前安全评测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvaluateBeforeInsurance evaluateBeforeInsurance)
    {
        List<EvaluateBeforeInsurance> list = evaluateBeforeInsuranceService.selectEvaluateBeforeInsuranceList(evaluateBeforeInsurance);
        ExcelUtil<EvaluateBeforeInsurance> util = new ExcelUtil<EvaluateBeforeInsurance>(EvaluateBeforeInsurance.class);
        util.exportExcel(response, list, "保前安全评测数据");
    }

    /**
     * 获取保前安全评测详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:insurance_before:query')")
    @GetMapping(value = "/{evaluateBeforeId}")
    public AjaxResult getInfo(@PathVariable("evaluateBeforeId") Long evaluateBeforeId)
    {
        return success(evaluateBeforeInsuranceService.selectEvaluateBeforeInsuranceByEvaluateBeforeId(evaluateBeforeId));
    }

    /**
     * 新增保前安全评测
     */
    @PreAuthorize("@ss.hasPermi('insurance:insurance_before:add')")
    @Log(title = "保前安全评测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluateBeforeInsurance evaluateBeforeInsurance)
    {
        return toAjax(evaluateBeforeInsuranceService.insertEvaluateBeforeInsurance(evaluateBeforeInsurance));
    }

    /**
     * 修改保前安全评测
     */
    @PreAuthorize("@ss.hasPermi('insurance:insurance_before:edit')")
    @Log(title = "保前安全评测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluateBeforeInsurance evaluateBeforeInsurance)
    {
        return toAjax(evaluateBeforeInsuranceService.updateEvaluateBeforeInsurance(evaluateBeforeInsurance));
    }

    /**
     * 删除保前安全评测
     */
    @PreAuthorize("@ss.hasPermi('insurance:insurance_before:remove')")
    @Log(title = "保前安全评测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evaluateBeforeIds}")
    public AjaxResult remove(@PathVariable Long[] evaluateBeforeIds)
    {
        return toAjax(evaluateBeforeInsuranceService.deleteEvaluateBeforeInsuranceByEvaluateBeforeIds(evaluateBeforeIds));
    }
}
